package com.tj.shopping.web.controller;

import com.alipay.api.domain.OrderDetail;
import com.tj.shopping.entity.Order;
import com.tj.shopping.entity.Orderdetail;
import com.tj.shopping.service.IOrderDetailService;
import com.tj.shopping.service.OrderService;
import com.tj.shopping.service.impl.OrderDetailServiceImpl;
import com.tj.shopping.service.impl.OrderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@WebServlet("/orderdetail")
public class OrderDetailController extends BaseController{
    private IOrderDetailService service=new OrderDetailServiceImpl();
    private OrderService orderService=new OrderServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        String op=req.getParameter("op");
        if ("add".equals(op)) {
            doAdd(req, resp);
        } else {
            resp.getWriter().print("no such method");
        }

    }

    //添加订单
    protected void doAdd(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Orderdetail orderdetail = parseRequest(req, Orderdetail.class);
        System.out.println(orderdetail);
        int ono = orderService.selectOno();
        orderdetail.setOno(ono);
        int result = service.add(orderdetail);
        printToJson(resp,result);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
